package com.kehutong.house.util;

import com.kehutong.common.errcode.Result;
import com.kehutong.house.app.DoorAction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * TODO
 *
 * @author zhouweipeng
 * @version 1.0
 * @date 2021/7/27 20:12
 */
public class DateUtils {
    private static Log log= LogFactory.getLog(DateUtils.class);
    public static final String PATTERN_1 = "yyyy-MM-dd HH:mm:ss";
    public static final String PATTERN_2 = "yyyyMMddHHmmss";
    public static final String PATTERN_3 = "yyyy-MM-dd";
    public static final String PATTERN_4 = "yyyyMMdd";
    /**
     * 将时间串转成Timestamp类型
     * @param str
     */
    public static Timestamp strFormatTimetamp(String str,String pattern) {
        DateFormat format = new SimpleDateFormat(pattern);
        format.setLenient(false);
        Timestamp ts =null;
        try {
            ts = new Timestamp(format.parse(str).getTime());
        } catch (ParseException e) {
            log.error("时间转换异常"+e.getMessage(),e);
        }
        return ts;
    }
    public static String timestampToStr(Timestamp timestamp,String pattern){
        DateFormat format = new SimpleDateFormat(pattern);
        format.setLenient(false);
        return format.format(timestamp);
    }
}
